﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using Quartz.Impl;

namespace Quartz.NET.WindowsFormsApp
{
    /// <summary>
    /// Quartz.NET 测试起始窗体
    /// </summary>
    public partial class FormStartup : Form
    {
        /// <summary>
        /// 初始化“Quartz.NET 测试起始窗体”
        /// </summary>
        public FormStartup()
        {
            InitializeComponent();
        }

        /// <summary>
        /// “Fluent Scheduler Builder API”按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonFluentSchedulerBuilderAPI_Click(object sender, EventArgs e)
        {
            //var scheduler = StdSchedulerFactory.GetDefaultScheduler();
            //scheduler.Start();
            //Thread.Sleep(TimeSpan.FromSeconds(10));
            //scheduler.Shutdown();
        }

        /// <summary>
        /// “HelloJob”按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonHelloJob_Click(object sender, EventArgs e)
        {
            var job = JobBuilder.Create<HelloJob>()
                .WithIdentity("job1", "group1")
                .Build();

            var trigger = TriggerBuilder.Create()
                .WithIdentity("trigger1", "group1")
                .StartNow()
                //.WithCronSchedule("0/3 * * * * ? *", builder => builder.WithMisfireHandlingInstructionDoNothing())
                .WithSimpleSchedule(builder =>
                {
                    builder.WithIntervalInSeconds(3)
                        //.WithMisfireHandlingInstructionNextWithRemainingCount()
                        .RepeatForever();
                })
                //.WithSchedule(CronScheduleBuilder.CronSchedule("0/3 * * * * ? *").WithMisfireHandlingInstructionDoNothing())
                .ForJob(job)
                .Build();

            var scheduler = StdSchedulerFactory.GetDefaultScheduler();
            scheduler.ScheduleJob(job, trigger);
        }
    }
}
